#include "../maindef.h"
#include "CTaskStatus.h"

int CTaskStatus::SetTaskFinished(CTaskID& stTaskID)
{
    if (stTaskID.IsMainTask())
    {
        _uiMainTaskStatus = CT_MAX(stTaskID._uiTaskID, _uiMainTaskStatus);

        CT_TRACE(("记录任务完成: 主线任务历史 %u", _uiMainTaskStatus));

        return 0;
    }

    //int iStatus = _astBranchTaskStatus[stTaskID._uiBranchID * MAX_TASK_BRANCHS + stTaskID._uiTaskID];

    while (_astBranchTaskStatus.Size() <= (int)stTaskID._uiBranchID)
    {
        _astBranchTaskStatus.AddOneItem(0);
    }

    unsigned char iStatus = _astBranchTaskStatus[stTaskID._uiBranchID];
    _astBranchTaskStatus[stTaskID._uiBranchID] = CT_MAX(iStatus, (unsigned char)(stTaskID._uiTaskID & 0x7F));

    CT_TRACE(("记录任务完成:  当前分支变化 %d , 当前分支任务历史 %d", 
                stTaskID._uiBranchID, _astBranchTaskStatus[stTaskID._uiBranchID]));

    return 0;
}

